use serde::{Deserialize, Serialize};

use crate::database::{self, table::menu::model::NewMenu};

#[derive(Debug, Serialize, Deserialize)]
pub struct MenuForm {
    pub id: i32,
    pub name: String,
    pub icon: String,
    pub link: String,
    pub visibility_level: i32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct NewMenuForm {
    pub name: String,
    pub icon: String,
    pub link: String,
    pub visibility_level: i32,
}

impl From<&database::table::menu::model::Menu> for MenuForm {
    fn from(menu: &database::table::menu::model::Menu) -> Self {
        MenuForm {
            id: menu.id,
            name: menu.name.clone(),
            icon: menu.icon.clone(),
            link: menu.link.clone(),
            visibility_level: menu.visibility_level,
        }
    }
}

impl MenuForm {
    pub fn to(&self) -> NewMenuForm {
        NewMenuForm {
            name: self.name.clone(),
            icon: self.icon.clone(),
            link: self.link.clone(),
            visibility_level: self.visibility_level,
        }
    }
}

impl NewMenuForm {
    pub fn to(&self) -> NewMenu {
        NewMenu {
            name: &self.name,
            icon: &self.icon,
            link: &self.link,
            visibility_level: self.visibility_level,
        }
    }
}
